package com.metagurukul.metagranth.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Validator {
	private Pattern pattern;
	private Matcher matcher;

	private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
	private static final String AGE_PATTERN = "^[0-9]{2}$";

	public Validator() {
	}

	/**
	 * emailValidate value with email regular expression
	 * 
	 * @param value
	 *            value for validation
	 * @return true valid value, false invalid value
	 */
	public boolean emailValidate(String value) {

		pattern = Pattern.compile(EMAIL_PATTERN);
		matcher = pattern.matcher(value);
		return matcher.matches();

	}

	public boolean passwordMatcher(String password,String confirmPassword)
	{
		if(password.equals(confirmPassword))
			return true;
		else
			return false;
	}

	/**
	 * ageValidate value with regular expression
	 * 
	 * @param value
	 *            value for validation
	 * @return true valid value, false invalid value
	 */
	public boolean ageValidate(String value) {

		pattern = Pattern.compile(AGE_PATTERN);
		matcher = pattern.matcher(value);
		return matcher.matches();

	}

	/**
	 * checkBlank checks value is blank or not
	 * 
	 * @param value
	 *            value for check
	 * @return true valid value, false invalid value
	 */
	public boolean checkBlank(String value) {
		boolean valid = false;
		if (!value.equals("")) {
			valid = true;
		}
		return valid;
	}
	
	public static boolean isNull(Object obj) {
		boolean isNull = false;
		if (obj != null) {
			if (obj instanceof String) {
				String value = (String) obj;
				if (value.isEmpty()) {
					isNull = true;
				} else {
					isNull = false;
				}
			}

		} else {
			isNull = true;
		}
		return isNull;
	}


	public boolean checkName() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean checkDate() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean checkTag() {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean nameValidate(String parameter) {
		// TODO Auto-generated method stub
		return true;
	}


}
